/**
 * 在它里面创建路由对象、设置路由规则，并且导出路由对象
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
// Vue.prototype.$route = 值
// Vue.prototype.$router = 值
Vue.use(VueRouter)

// 导入路由切换的页面
import FoodsList from '../views/FoodsList'
import FoodDetail from '../views/FoodDetail'
import NewsList from '../views/NewsList'
import NewsDetail from '../views/NewsDetail'
import NotFound from '../views/NotFound'

const router = new VueRouter({
  // routes，单词最好用插件提示，不要写错了
  routes: [
    // {
    //   path: '/',
    //   component: NewsList
    // },
    // 规则是一个一个的对象
    {
      path: '/foodslist',
      component: FoodsList
    },
    {
      path: '/newslist',
      component: NewsList
    },
    {
      path: '/',
      redirect: '/newslist'
    },
    {
      path: '/fooddetail',
      component: FoodDetail
    },
    {
      // 动态路径参数 以冒号开头
      path: '/newsdetail/:id/:name',
      component: NewsDetail
    },
    // 404 配置
    {
      path: '*',
      component: NotFound
    }
  ]
})

export default router
